package com.hjk.common.utils.log;

import lombok.extern.slf4j.Slf4j;

/**
 * 输出代码执行位置
 */
@Slf4j
public class LogUtil {
    private static StringBuilder sb = new StringBuilder();

    /**
     * 打印日志 代码位置   (LogLocalityUtil.java:26)
     * @return
     */
    public static String getLocal(){
        if(sb != null){
            sb.setLength(0);
        }
        StackTraceElement[] trace = Thread.currentThread().getStackTrace();
        StackTraceElement tmp = trace[2];
        return sb.append(tmp.getMethodName())
                .append("(")
                .append(tmp.getFileName())
                .append(":")
                .append(tmp.getLineNumber())
                .append(")").toString();
    }

    public static void main(String[] args) {

        log.info(LogUtil.getLocal());
    }
}
